// 学生接口定义
export interface Student {
  id: number;
  studentId: string;
  name: string;
  gender: string;
  age: number;
  major: string;
  class: string;
  admissionYear: string;
  phone: string;
  email: string;
  address: string;
  status: string;
  marketingDepartment: string;
  dormitory?: string;
  birthDate?: string;
  idCardNumber?: string;
  college?: string;
  counselor?: string;
  lecturer?: string;
  score?: number;
  absenceCount?: number;
  // 成绩相关字段
  examScores?: { month: string; score: number; rank: number }[];
  // 评语相关字段
  semesterComments?: { semester: string; comment: string }[];
}

// 模拟学生数据
export let mockStudents: Student[] = [
  {
    id: 1,
    studentId: '2023001',
    name: '张三',
    gender: '男',
    age: 19,
    major: '计算机科学与技术',
    class: '2412A',
    admissionYear: '2023',
    phone: '13800138001',
    email: 'zhangsan@example.com',
    address: '北京市海淀区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-101',
    birthDate: '2004-05-15',
    idCardNumber: '110101200405151234',
    college: '计算机科学与技术学院',
    counselor: '李老师',
    lecturer: '张教授',
    score: 85,
    absenceCount: 0
  },
  {
    id: 2,
    studentId: '2023002',
    name: '李四',
    gender: '女',
    age: 18,
    major: '软件工程',
    class: '2411B',
    admissionYear: '2023',
    phone: '13800138002',
    email: 'lisi@example.com',
    address: '上海市浦东新区',
    status: '在读',
    marketingDepartment: '保仓市场部',
    dormitory: '女生1号楼-201',
    birthDate: '2005-03-20',
    idCardNumber: '310101200503205678',
    college: '电子工程学院',
    counselor: '王老师',
    lecturer: '刘教授',
    score: 90,
    absenceCount: 1
  },
  {
    id: 3,
    studentId: '2023003',
    name: '王五',
    gender: '男',
    age: 20,
    major: '数据科学',
    class: '2411A',
    admissionYear: '2023',
    phone: '13800138003',
    email: 'wangwu@example.com',
    address: '广州市天河区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-101',
    birthDate: '2003-09-10',
    idCardNumber: '440101200309109012',
    college: '计算机科学与技术学院',
    counselor: '李老师',
    lecturer: '赵教授',
    score: 78,
    absenceCount: 2
  },
  {
    id: 4,
    studentId: '2023004',
    name: '赵六',
    gender: '女',
    age: 19,
    major: '信息工程',
    class: '2411B',
    admissionYear: '2023',
    phone: '13800138004',
    email: 'zhaoliu@example.com',
    address: '广州市海珠区',
    status: '在读',
    marketingDepartment: '保仓市场部',
    dormitory: '女生1号楼-201',
    birthDate: '2004-12-05',
    idCardNumber: '440101200412053456',
    college: '电子工程学院',
    counselor: '王老师',
    lecturer: '陈教授',
    score: 92,
    absenceCount: 0

  },{
    id: 5,
    studentId: '2023005',
    name: '王二',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2412B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '休学',
    
    marketingDepartment: '黑吉市场部',
    dormitory: '男生1号楼-102',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '鸿蒙学院',
    counselor: '孙老师',
    lecturer: '杨教授',
    score: 75,
    absenceCount: 3

  },
 {
     id: 6,
    studentId: '2023006',
    name: '刘壮',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2412B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '退学',
    marketingDepartment: '黑吉市场部',
    dormitory: '男生1号楼-102',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '鸿蒙学院',
    counselor: '孙老师',
    lecturer: '杨教授',
    score: 65,
    absenceCount: 5

 },
 {
    id: 7,
    studentId: '2023007',
    name: 'qiqi',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2412B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '黑吉市场部',
    dormitory: '男生1号楼-102',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '鸿蒙学院',
    counselor: '孙老师',
    lecturer: '杨教授',
    score: 88,
    absenceCount: 1

 },{
    id: 8,
    studentId: '2023008',
    name: 'mg',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2412B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '毕业',
    marketingDepartment: '辽冀市场部',
    dormitory: undefined,
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院',
    counselor: '钱老师',
    lecturer: '孙教授',
    score: 95,
    absenceCount: 0

 },{
    id: 9,
    studentId: '2023009',
    name: 'cc',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2411B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-103',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院',
    counselor: '王老师',
    lecturer: '刘教授',
    score: 82,
    absenceCount: 2

 },{
    id: 10,
    studentId: '2023010',
    counselor: '李老师',
    lecturer: '张教授',
    score: 88,
    absenceCount: 1,
    name: 'ded',
    gender: '男',
    age: 21,
    major: '信息工程',
    class: '2411B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-102',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院'

 },
 {
    id: 11,
    studentId: '2023011',
    name: 'cc',
    gender: '男',
    age: 21,
    major: '人工智能',
    class: '2411B',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-103',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院'

 },
 {
    id: 12,
    studentId: '2023012',
    name: 'fsfd',
    gender: '男',
    age: 21,
    major: '人工智能',
    class: '2411A',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-103',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院'

 },
 {
    id: 13,
    studentId: '2023013',
    name: 'fsfd',
    gender: '男',
    age: 21,
    major: '人工智能',
    class: '2412A',
    admissionYear: '2023',
    phone: '13800138005',
    email: 'wanger@example.com',
    address: '广州市番禺区',
    status: '在读',
    marketingDepartment: '辽冀市场部',
    dormitory: '男生1号楼-103',
    birthDate: '2002-07-22',
    idCardNumber: '440101200207227890',
    college: '人工智能学院'

 },
];

// 获取所有学生数据
export const getStudents = async (): Promise<Student[]> => {
  // 模拟API延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(mockStudents);
    }, 300);
  });
};

// 添加新学生
export const addStudent = async (student: Omit<Student, 'id'>): Promise<Student> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const newStudent: Student = {
        ...student,
        id: Math.max(...mockStudents.map(s => s.id)) + 1
      };
      mockStudents.push(newStudent);
      resolve(newStudent);
    }, 300);
  });
};

// 更新学生信息
export const updateStudent = async (id: number, updatedData: Partial<Student>): Promise<Student | null> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const index = mockStudents.findIndex(s => s.id === id);
      if (index !== -1) {
        mockStudents[index] = { ...mockStudents[index], ...updatedData };
        resolve(mockStudents[index]);
      } else {
        resolve(null);
      }
    }, 300);
  });
};

// 删除学生
export const deleteStudent = async (id: number): Promise<boolean> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const initialLength = mockStudents.length;
      mockStudents = mockStudents.filter(s => s.id !== id);
      resolve(mockStudents.length < initialLength);
    }, 300);
  });
};